<?php
/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
defined ('IN_AGORA') or die;

class TaskController extends AgoraProfileController {
    function _default() {

        $style = $this->agora_config['o_default_style'];
        $document = & JFactory::getDocument ();

        $my = & JFactory::getUser();
        $user_helper = &$this->helper('user');
        $this->user = $user_helper->prepareUserTitle($this->user);

        $gallery_path =  'components/com_agora/img/members/' . $this->user['id'];
        $files = $this->getFilesystemFilesFromFolder('components'.DS.'com_agora'.DS.'img'.DS.'members'.DS.$this->user['id'], $gallery_path, $this->toShow());
		$gallery_path =  '/' . $gallery_path;

        $this->view->assign('gallery_path',$gallery_path);
        $this->view->assign('images',$files);
        $this->view->assign('user_id',$this->user['id']);
		
		/*
        $document->addScript(JURI::base () . 'components' . '/' . 'com_agora' . '/' . 'js' . '/' . 'pikachoose-min.js');
        $document->addStyleSheet(JURI::base () . 'components' . '/' . 'com_agora' . '/' . 'style' . '/' . $style . '/' . 'js_css' . '/' . 'gallery.css');
        $document->addScriptDeclaration('$j(document).ready(function (){$j("#pikame").PikaChoose({show_captions:true, slide_enabled:true, auto_play: false, thumb_width:75, thumb_height:75});});');
		*/

		// by ElvisVinicius
		//$thumbSize = $this->agora_config['o_uploadile_thumb_size'] + 10;
		$jss = 'window.addEvent(\'domready\', function() { $$("a.agImageGalleryThumbs").slimbox(); });';
		$css = "
			#agImageGalleryThumbsContainer { padding:10px;background:#111;overflow:hidden; }
			#agImageGalleryThumbs { padding:0; margin:0; float:left; width:100%; list-style:none; }
			#agImageGalleryThumbs li { padding:0; margin:0 2px 2px 0; float:left; }
			#agImageGalleryThumbs div { padding:2px 0;margin:2px 0 0 0;border:1px solid #333;background:#222;text-align:center!important; }
			a.agImageGalleryThumbs { padding:2px; width:{$this->agora_config['o_uploadile_thumb_size']}px; height:{$this->agora_config['o_uploadile_thumb_size']}px; border:1px solid #333; display:block; cursor:pointer; overflow:hidden; text-align:center!important; vertical-align:middle!important; }
			a.agImageGalleryThumbs:hover { border:1px solid #eee; }
			a.agImageGalleryThumbs img { border:none!important; }
		";

        $document->addScriptDeclaration($jss);
        $document->addStyleDeclaration($css);

        $this->view->assign('icon_path', JURI::base().'components/com_agora/img/icons/');
    }
	
    function toShow() {
	
        $ret = false;
        $my = & JFactory::getUser();

		if ($this->user['username']== $my->username) {
            $ret = true;
        } else {
            $ret= false;
        }

        return $ret;

    }

    function getFilesystemFilesFromFolder($folder, $path, $show = true) {
	
        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');
        $files = array();
		
        // by ElvisVinicius
        $mimetypes = array('jpg', 'jpeg', 'png', 'gif');

        if (JFolder::exists(JPATH_BASE.DS.$folder)) {
            $fileList = JFolder::files(JPATH_BASE.DS.$folder);
            if (count($fileList) > 0) {
                foreach($fileList as $file) {
                    if (!strstr( strtolower($file), 'mini')){
						$files['name'][] = $file;
                        if ($show==true){
                            //if ( strtolower(JFile::getExt($file)) == 'jpg' || strtolower(JFile::getExt($file)) == 'png' || strtolower(JFile::getExt($file)) =='gif' || ) {
                            if (in_array(strtolower(JFile::getExt($file)), $mimetypes)) {
                                //$files[] = JURI::base (false) .$folder. DS.$file;
                                // by ElvisVinicius
                                $_thumbSize = getimagesize(JPATH_SITE . DS . $folder. DS . 'mini_'.$file);

                                $files['imageFull'][] = JURI::base (false) . $path . '/' .$file;
                                $files['imageThumb'][] = JURI::base (false) . $path . '/' .'mini_'.$file;
                                $files['imageThumbSize'][] = $_thumbSize[3];

                                unset($_thumbSize);
                            }
                        }else{
                            if (!strstr(strtolower($file), 'hide')){
                                //if ( strtolower(JFile::getExt($file)) == 'jpg' || strtolower(JFile::getExt($file)) == 'png' || strtolower(JFile::getExt($file)) =='gif') {
                                if (in_array(strtolower(JFile::getExt($file)), $mimetypes)) {
                                    //$files[] = JURI::base (false) .$folder. DS.$file;
                                    // by ElvisVinicius
                                    $files['imageFull'][] = JURI::base (false) . $path . '/' .$file;
                                    $files['imageThumb'][] = JURI::base (false) . $path . '/' .'mini_'.$file;
                                }
                            }
                        }
                    }
                }
            }
        }

        return $files;
    }

}

?>
